﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YABE.Models;
using YABE.Validators;

namespace YABETests.ValidationTests
{
    /// <summary>
    /// Summary description for PostValidations
    /// </summary>
    [TestClass]
    public class PostValidations
    {
        public PostValidations()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod()]
        public void EmptyTitleShouldCause_PostTitleValidationError()
        {
            Post post = new Post();
            RuleViolation checkTitleViolation = post.CheckTitleValidation();
            Assert.IsNotNull(checkTitleViolation);
            Assert.AreEqual("PostTitleEmpty",checkTitleViolation.PropertyName);
            Assert.AreEqual("Post title can't be empty",checkTitleViolation.ErrorMessage);
        }

        [TestMethod]
        public void FilledTitleShouldNOTCause_PostTitleValidationError()
        {
            Post post = new Post();
            post.Title = "TEST";
            RuleViolation checkTitleViolation = post.CheckTitleValidation();
            Assert.IsNull(checkTitleViolation);
        }

        [TestMethod()]
        public void EmptyBodyShouldCause_PostBodyValidationError()
        {
            Post post = new Post();
            RuleViolation checkBodyViolation = post.CheckBodyValidation();
            Assert.IsNotNull(checkBodyViolation);
            Assert.AreEqual("PostBodyEmpty",checkBodyViolation.PropertyName);
            Assert.AreEqual(ErrorMessages.PostBodyEmpty,checkBodyViolation.ErrorMessage);
        }

        [TestMethod()]
        public void FilledBodyShouldNOTCause_PostBodyValidationError()
        {
            Post post = new Post();
            post.Body = "TEST";
            RuleViolation checkBodyViolation = post.CheckBodyValidation();
            Assert.IsNull(checkBodyViolation);
        }
        
        [TestMethod()]
        public void PostGetRuleViolationShouldHave_TitleViolationOnly()
        {
            Post post = new Post();
            post.Body = "TEST";
            List<RuleViolation> violations = post.GetRuleViolations();
            Assert.IsNotNull(violations);
            Assert.IsTrue(violations.Count==1);
            Assert.AreEqual("PostTitleEmpty", violations[0].PropertyName);
            Assert.AreEqual(ErrorMessages.PostTitleEmpty, violations[0].ErrorMessage);
        }

        [TestMethod()]
        public void PostGetRuleViolationShouldHave_BodyRuleViolationOnly()
        {
            Post post = new Post();
            post.Title = "TEST";
            List<RuleViolation> violations = post.GetRuleViolations();
            Assert.IsNotNull(violations);
            Assert.IsTrue(violations.Count == 1);
            Assert.AreEqual("PostBodyEmpty", violations[0].PropertyName);
            Assert.AreEqual(ErrorMessages.PostBodyEmpty, violations[0].ErrorMessage);
        }
    }
}
